package com.typhoon.spring_shiro.service;

import com.typhoon.spring_shiro.dto.StockDto;
import com.typhoon.spring_shiro.dto.request.StockReq;
import com.typhoon.spring_shiro.dto.response.StockResp;

/**
 * 库存接口
 * 
 * @author Typhoon
 * @date 2017-07-11 12:00 Tuesday
 * @since V1.3.0
 */
public interface StockService extends IBaseService<StockDto, Long> {
	
	/**
	 * redis缓存中待扣除库存的key前缀
	 */
	String CACHE_STOCK_WAITING_FOR_DEDUCT_PREFIX= "cache_stock_waiting_for_deduct:";
	
	/**
	 * 扣减库存
	 * 
	 * @author Typhoon
	 * @date 2017-07-11 12:00
	 * @since V1.3.0
	 * @param req
	 * @return
	 */
	StockResp deductStock(StockReq req);
	
	/**
	 * 增加库存
	 * 
	 * @author Typhoon
	 * @date 2017-07-11 16:05
	 * @since V1.3.0
	 * @param req
	 * @return
	 */
	StockResp increaseStock(StockReq req);
	
	/**
	 * 扣减库存另外一种解决方式
	 * 
	 * @author Typhoon
	 * @date 2017-07-11 20:10 Tuesday
	 * @since V1.3.0
	 * @param req
	 * @return
	 */
	@Deprecated
	StockResp deductStockV2(StockReq req);
	
	/**
	 * 获取待派发的库存量
	 * 
	 * @author Typhoon
	 * @date 2017-07-11 20:16 Tuesday
	 * @since V1.3.0
	 * @param stockId
	 * @return
	 */
	int getStockWaitingForDeduct(Long stockId);
	
	/**
	 * 处理库存待扣减值
	 * 
	 * @author Typhoon
	 * @date 2017-07-11 20:33
	 * @since V1.3.0
	 * @param stockId
	 * @param amount
	 * @return
	 */
	long handleStockWaitingForDeduct(Long stockId,int amount);
	
	/**
	 * 并发扣减库存
	 * 
	 * @author Typhoon
	 * @date 2017-07-12 13:48 Wednesday
	 * @since V1.3.0
	 * @param req
	 * @return
	 */
	StockResp deductStockV3(StockReq req);
	
	/**
	 * 并发扣减库存
	 * 
	 * @author Typhoon
	 * @date 2017-07-12 20:27 Wednesday
	 * @since V1.3.0
	 * @param req
	 * @return
	 */
	StockResp deductStockV4(StockReq req);
	
	/**
	 * 并发扣减库存
	 * 
	 * @author Typhoon
	 * @date 2017-07-12 21:01 Wednesday
	 * @since V1.3.0
	 * @param req
	 * @return
	 */
	StockResp deductStockV5(StockReq req);

}
